import urllib.request
from urllib.request import urlretrieve
import getimage
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
url='https://www.tute.edu.cn/xysh/yxtzsd/1.htm'
response=urllib.request.urlopen(url)
quan=" "
quan=response.read().decode('utf-8')
print(quan)
#step2 从页面内容提取网址
list1=getimage.getimg(quan)
print("总共找到了{0}张图片",format(len(list1)))
#step3：根据网址下载图片
num=int(input("请输入要下载图片数"))
for i in range(num):
    urlretrieve(list1[i],'img{0}.jpg'.format(i))
print(("下载成功"))

def save_files(url,index):
    request=urllib.request.Request(url)
    request.add_header('user-Agent','Mozilla/5.0 (Windows NT 10.0; Win64;x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36')
    response=urllib.request.urlopen(request)
    img=response.read()

    with open('tute_'+str(index)+'.jpg','wb') as f:
        f.write(img)
